package cn.shengongying.api.dto;

import cn.shengongying.model.Customer;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * author: RXK
 * date: 2022/1/7 星期五
 * desc:
 */
@Getter
@Setter
@ApiModel(value = "雇主入参")
public class BossInDTO {

    @ApiModelProperty(value = "昵称")
    private String nickName;

    @ApiModelProperty(value = "签名")
    private String signature;

    @ApiModelProperty(value = "头像地址")
    private String img;

    @ApiModelProperty(value = "性别(0:男;1:女)")
    private Integer sex;

    @ApiModelProperty(value = "手机号")
    private String phone;

    @ApiModelProperty(value = "生日(时间戳)")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date birthday;

    @ApiModelProperty(value = "收货地址")
    private String address;

    @ApiModelProperty(value = "雇主类别(0:加工商;1:模具商;2:设备商)")
    private Integer category;

    @ApiModelProperty(value = "成立时间(时间戳)")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date establishedTime;

    public  Customer build(Long userId) {
        Customer customer = new Customer();
        boolean change = false;
        if (StringUtils.isNotEmpty(nickName)) {
            change = true;
            customer.setNickName(nickName);
        }

        if (StringUtils.isNotEmpty(img)) {
            change = true;
            customer.setImg(img);
        }

        if (StringUtils.isNotEmpty(signature)) {
            change = true;
            customer.setSignature(signature);
        }

        if (null != sex) {
            change = true;
            customer.setSex(sex);
        }

        if (StringUtils.isNotEmpty(phone)) {
            change = true;
            customer.setPhone(phone);
        }

        if (StringUtils.isNotEmpty(address)) {
            change = true;
            customer.setAddress(address);
        }

        if (null != category) {
            change = true;
            customer.setCategory(category);
        }

        if (null != birthday) {
            change = true;
            customer.setBirthday(birthday);
        }

        if (null != establishedTime) {
            change = true;
            customer.setEstablishedTime(establishedTime);
        }

        if (change) {
            customer.setId(userId);
        } else {
            customer = null;
        }

        return customer;
    }
}
